#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, a, b, c, dist[5001], f[3][5001];
struct Node {
	ll y, v;
	Node(int _y, int _v) {
		y = _y, v = _v;
	};
};
vector<Node> edge[10001];
set < pair<ll, ll>> q;
inline void dijkstra(ll s) {
	memset(dist, 127, sizeof(dist));
	dist[s] = 0;
	q.clear(); 
	for (ll i = 1; i <= n; ++i)
		q.insert({dist[i], i});
	for (; !q.empty(); ) {
		ll x = q.begin()->second;
		q.erase(q.begin());
		for (auto i : edge[x])
			if (dist[x] + i.v < dist[i.y]) {
				q.erase({dist[i.y], i.y});
				dist[i.y] = dist[x] + i.v;
				q.insert({dist[i.y], i.y});
			}
	}
}
int main() {
	scanf("%lld%lld", &n, &m);
	for (ll i = 1; i <= m; ++i) {
		ll x, y, z;
		scanf("%lld%lld%lld", &x, &y, &z);
		edge[x].push_back(Node(y, z));
		edge[y].push_back(Node(x, z));
	}
	scanf("%lld%lld%lld", &a, &b, &c);
	dijkstra(a);
	memcpy(f[0], dist, sizeof(dist));
	dijkstra(b);
	memcpy(f[1], dist, sizeof(dist));
	dijkstra(c);
	memcpy(f[2], dist, sizeof(dist));
	ll ans = 1 << 30;
	for (ll i = 1; i <= n; ++i)
		ans = min(ans, f[0][i] + f[1][i] + f[2][i]);
	printf("%lld\n", ans);
	return 0;
}
